package com.itheima.tliasmanagent.service.impl;


import com.itheima.tliasmanagent.mapper.DeptMapper;
import com.itheima.tliasmanagent.pojo.Dept;
import com.itheima.tliasmanagent.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

// 处理数据 业务逻辑处理
//@Component
@Service
//@Primary
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> getDeptList(){
        List<Dept> depts = deptMapper.queryDepts();
        return depts;
    }

    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    @Override
    public void add(Dept dept) {

        // 补全属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.saveDept(dept);
    }

    @Override
    public Dept getInfo(Integer id) {

        Dept dept= deptMapper.getById(id);
        return dept;
    }

    @Override
    public void update(Dept dept) {
        // 补全属性
        dept.setUpdateTime(LocalDateTime.now());

        deptMapper.update(dept);
    }


}
